import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter);

const routes = [{
        path: '/',
        name: 'index',
        component: () => import('@/pages/login/login'),
        redirect: '/login',
        meta: {
            title: '在线考试系统'
        }
    },

    {
        path: '/login',
        name: 'login',
        meta: {
            title: '在线考试系统'
        },
        component: () => import('@/pages/login/login')
    },
    {
        path: '/majorClass',
        name: 'majorClass',
        meta: {
            title: '在线考试系统'
        },
        component: () => import('@/pages/majorClass/majorClass')
    },
    {
        path: '/batchList',
        name: 'batchList',
        meta: {
            title: '在线考试系统'
        },
        component: () => import('@/pages/batchList/batchList')
    },
    {
        path: '/testList',
        name: 'testList',
        meta: {
            title: '在线考试系统'
        },
        component: () => import('@/pages/testList/testList')
    },
    {
        path: '/testValid',
        name: 'testValid',
        meta: {
            title: '在线考试系统'
        },
        component: () => import('@/pages/testValid/testValid')
    },
    {
        path: '/userInfo',
        name: 'userInfo',
        meta: {
            title: '在线考试系统'
        },
        component: () => import('@/pages/userInfo/userInfo')
    },
];

const router = new VueRouter({
    routes,
    mode: 'hash',
    scrollBehavior() {
        return {
            x: 0,
            y: 0
        }
    },
    linkExactActiveClass: 'my_active'
});

//跳转前拦截
router.beforeEach((to, from, next) => {
    //设置title
    if (to.meta.title) {
        document.title = to.meta.title;
    }
    next();
});

//跳转后拦截
router.afterEach(() => {

});
export default router;